/** axios封装
 * 请求拦截、相应拦截、错误统一处理
 */
import axios from './axios' // 导入request中创建的axios实例

console.log(import.meta.env.VITE_MODE_NAME)
const baseUrl = import.meta.env.VITE_API_DOMAIN
const request = {
  post(url: string, data?: any, type?: string) {
    if (type === 'upload') {
      let uploadUrl = url
      if (import.meta.env.VITE_MODE_NAME === 'production') {
        uploadUrl = url.replace(/^\/uploadImage/, 'http://test1.xunmengvip.com:7720')
      }
      return axios({
        method: 'POST',
        url: uploadUrl,
        data,
        headers: { 'Content-Type': 'multipart/form-data' }
      })
    }
    return axios({
      method: 'POST',
      url: `${baseUrl}${url}`,
      data,
      headers: { 'Content-Type': 'application/json', user_token_xm: localStorage.token }
    })
  },
  get(url: string, data: any) {
    return axios({
      method: 'GET',
      url: `${baseUrl}${url}`,
      params: data,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        user_token_xm: localStorage.token
      }
    })
  }
}
export default request
// export default instance;
